﻿
namespace MoneyBook.Web.Services {
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.Linq;
    using System.ServiceModel.DomainServices.EntityFramework;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;
    using MoneyBook.Web.Models;


    // Implements application logic using the MoneyBookEntities context.
    // TODO: Add your application logic to these methods or in additional methods.
    // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
    // Also consider adding roles to restrict access as appropriate.
    // [RequiresAuthentication]
    [EnableClientAccess()]
    public class AccountMemberService : LinqToEntitiesDomainService<MoneyBookEntities> {

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'AccountMembers' query.
        public IQueryable<AccountMember> GetAccountMembers() {
            return this.ObjectContext.AccountMembers;
        }

        public void InsertAccountMember(AccountMember accountMember) {
            if ((accountMember.EntityState != EntityState.Detached)) {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(accountMember, EntityState.Added);
            } else {
                this.ObjectContext.AccountMembers.AddObject(accountMember);
            }
        }

        public void UpdateAccountMember(AccountMember currentAccountMember) {
            this.ObjectContext.AccountMembers.AttachAsModified(currentAccountMember, this.ChangeSet.GetOriginal(currentAccountMember));
        }

        public void DeleteAccountMember(AccountMember accountMember) {
            if ((accountMember.EntityState == EntityState.Detached)) {
                this.ObjectContext.AccountMembers.Attach(accountMember);
            }
            this.ObjectContext.AccountMembers.DeleteObject(accountMember);
        }
    }
}


